<?php

namespace App\Http\Controllers;

use App\Repositories\Contracts\FlightDynamicInterface;
use Illuminate\Http\Request;
use MakeRep\Controllers\BaseController;
use MakeRep\Resources\BaseCollection;
use MakeRep\Services\ParamService;

class FlightDynamicController extends BaseController
{
    public function __construct(FlightDynamicInterface $interface)
    {
        parent::__construct($interface);
    }


    /**
     * 列表
     * @param Request $request
     * @return BaseCollection
     */
    public function ajaxLists(Request $request){

        $pageSize = $request->page_size ? : 365;
        $orderBy = $request->order_by ? : 'desc';

        $where = [];
        if ($request->start_at){
            $where[] = ['created_at','>=',substr($request->start_at,0,10)];
        } else {

            $where[] = ['created_at','>=',date('Y-m-d',strtotime('-1month'))];
        }

        $where = array_merge(ParamService::createCondition($request,isset($this->interface->fillable) ? $this->interface->fillable : []),$where);

        $res = $this->interface->pageLists($where,'*',$pageSize,'id',$orderBy);
        return new BaseCollection($res);
    }
}